﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MenuLib
{
    public static class Extensions
    {
        public static bool RemoveFirstByValue<K, V>(
            this Dictionary<K, V> items, Func<V, bool> pred)
        {
            KeyValuePair<K, V> removedItem = items.FirstOrDefault(
                (KeyValuePair<K, V> pair) => pred(pair.Value));

            if (null != removedItem.Value)
            {
                items.Remove(removedItem.Key);
                return true;
            }

            return false;
        }
    }
}
